import $service from '../../../../service'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isagreen: false,
    idCard: '',
    name: '',
    phone: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    this.setData({
      phone: e.phone
    })
  },
  //协议选择框
  choosetap() {
    this.setData({
      isagreen: !this.data.isagreen
    })
  },
  // 前往协议页
  gotopage(e) {
    let {
      type
    } = e.currentTarget.dataset
    $service.openPage(`../../../login/agreement/agreement?type=${type}`)
  },
  inputChange(e) {
    let {
      type
    } = e.currentTarget.dataset
    let {
      value
    } = e.detail
    this.data[type] = value
    this.setData({
      name: this.data.name,
      phone: this.data.phone,
      idCard: this.data.idCard,
    })
  },
  next() {
    let {name, idCard, phone, isagreen} = this.data
    if (!name) {
      $service.showToast('请输入真实姓名')
      return
    }
    if (!idCard) {
      $service.showToast('请输入身份证号')
      return
    }
    if (!$service.validateElement('idCard', idCard)) {
      $service.showToast('请输入正确的身份证号');
      return;
    }
    if (!phone) {
      $service.showToast('请输入手机号')
      return
    }
    if (!$service.validateElement('mobile', phone)) {
      $service.showToast('请输入正确的手机号！');
      return;
    }
    if (!isagreen) {
      $service.showToast('请详细阅读并勾选《医生须知》');
      return;
    }
    let params = {
      "documentNumber": idCard,
      "mobile": phone,
      "name": name
    }
    app.http.individualTelecom3Factors(params).then(res => {
      params.flowId = res.data.flowId
      wx.redirectTo({
        url: `../phoneVerify/phoneVerify?info=${JSON.stringify(params)}`,
      })
      // $service.openPage(`../phoneVerify/phoneVerify?info=${JSON.stringify(params)}`)
    }).catch(err => {
      $service.showToast(err.msg)
    })
  }
})